package com.javasea.websocket.web;

import com.google.common.collect.Maps;
import com.javasea.websocket.entity.JsonMessage;
import com.javasea.websocket.entity.SessionUser;
import com.javasea.websocket.service.LoginUserCache;
import com.javasea.websocket.utils.WsBroadcastUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 *@ClassName WebSocketController
 *@Description 正式环境测试：https://www.kbmis.yjtjckj.com/lmwy-kebao/api/oauth/websocket/getUserSession
 *@Author longxiaonan@163.com
 *@Date 2020/10/31 0031 12:30
 */
@RestController
@RequestMapping("/websocket")
public class WebSocketController {

    @GetMapping("/getUserSession")
    public Map<String, String> getUserSession(){
        Map<String, SessionUser> allByMap = LoginUserCache.getAllByMap();
        Map<String, String> resultMap = Maps.newHashMap();
        allByMap.forEach((k,v) ->{
            resultMap.put(k, v.getUserName());
        });
        // 添加注释
        return resultMap;
    }

    @GetMapping("/testSend")
    public void testSend(){
        WsBroadcastUtil.broadcastNotifications("838f2660cd9511ea9c550800276b1419", new JsonMessage("test", "test", "","",""));
    }

}
